﻿/*
=============================================================================
Author:魏宝辉通过CodeSmithe生成
CreatedTime:2012-8-10
Description:Sms_Log.aspx.cs页面代码
=============================================================================	
*/

using System;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using FTchina;

public partial class Sms_Log : System.Web.UI.Page
{


    string TableName = "Sms_Log";//表名
    static string SqlWhere = " 1=1 ";//过滤条件
    string GetCountSql = "select count(id)  from Sms_Log where " + SqlWhere;
    string SqlTable = "select *  from Sms_Log where " + SqlWhere + "  order by id desc ";
    string ReturnPage = "Sms_Log.aspx";

    string SearchFilter = " and scontent like '%{0}%' ";

    FTchina.SearchQuery.QueryModel qm = new FTchina.SearchQuery.QueryModel();//实例化模型

    protected void Page_Load(object sender, EventArgs e)
    {
        FTchina.basic.CheckAdmin(this);
        FTchina.basic.ChkPoewr(this, FTchina.Api.htmlpath.GetCurrentPagePath());
        if (!IsPostBack)
        {


            if (qm.WorkPage != ReturnPage)
            {
                qm.Key1 = string.Empty;
                BindQuerySearchModel(SqlWhere, GetCountSql, SqlTable);


            }
            else
            {

                bindData(qm);
            }
        }
    }


    /// <summary>
    /// 发送成功
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnSsuc_Click(object sender, EventArgs e)
    {
        string SqlWhere = " state =1  ";//过滤条件
        if (txbsearch.Text.Trim().Length > 0)
        {
            qm.Key1 = txbsearch.Text.Trim();
            SqlWhere += string.Format(SearchFilter, qm.Key1);
        }
        string GetCountSql = "select count(id)  from Sms_Log where " + SqlWhere;
        string SqlTable = "select *  from Sms_Log where " + SqlWhere + "  order by id desc ";
        BindQuerySearchModel(SqlWhere, GetCountSql, SqlTable);

    }
    /// <summary>
    /// 发送失败
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnSfail_Click(object sender, EventArgs e)
    {
        string SqlWhere = " state =0  ";//过滤条件
        if (txbsearch.Text.Trim().Length > 0)
        {
            qm.Key1 = txbsearch.Text.Trim();
            SqlWhere += string.Format(SearchFilter, qm.Key1);
        }
        string GetCountSql = "select count(id)  from Sms_Log where " + SqlWhere;
        string SqlTable = "select *  from Sms_Log where " + SqlWhere + "  order by id desc ";

        BindQuerySearchModel(SqlWhere, GetCountSql, SqlTable);

    }

    /// <summary>
    /// 拉取失败
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnLno_Click(object sender, EventArgs e)
    {
        string SqlWhere = " taskstate =0  ";//过滤条件
        if (txbsearch.Text.Trim().Length > 0)
        {
            qm.Key1 = txbsearch.Text.Trim();
            SqlWhere += string.Format(SearchFilter, qm.Key1);
        }
        string GetCountSql = "select count(id)  from Sms_Log where " + SqlWhere;
        string SqlTable = "select *  from Sms_Log where " + SqlWhere + "  order by id desc ";

        BindQuerySearchModel(SqlWhere, GetCountSql, SqlTable);
    }
    /// <summary>
    /// 审核禁止
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnSno_Click(object sender, EventArgs e)
    {
        string SqlWhere = " shenhe =0  ";//过滤条件
        if (txbsearch.Text.Trim().Length > 0)
        {
            qm.Key1 = txbsearch.Text.Trim();
            SqlWhere += string.Format(SearchFilter, qm.Key1);
        }
        string GetCountSql = "select count(id)  from Sms_Log where " + SqlWhere;
        string SqlTable = "select *  from Sms_Log where " + SqlWhere + "  order by id desc ";

        BindQuerySearchModel(SqlWhere, GetCountSql, SqlTable);
    }
    /// <summary>
    /// 审核通过
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnsok_Click(object sender, EventArgs e)
    {
        string SqlWhere = " shenhe =1  ";//过滤条件
        if (txbsearch.Text.Trim().Length > 0)
        {
            qm.Key1 = txbsearch.Text.Trim();
            SqlWhere += string.Format(SearchFilter, qm.Key1);
        }
        string GetCountSql = "select count(id)  from Sms_Log where " + SqlWhere;
        string SqlTable = "select *  from Sms_Log where " + SqlWhere + "  order by id desc ";
        BindQuerySearchModel(SqlWhere, GetCountSql, SqlTable);
    }

    /// <summary>
    /// 自动放行
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnsauto_Click(object sender, EventArgs e)
    {
        string SqlWhere = " shenhe =2  ";//过滤条件
        if (txbsearch.Text.Trim().Length > 0)
        {
            qm.Key1 = txbsearch.Text.Trim();
            SqlWhere += string.Format(SearchFilter, qm.Key1);
        }
        string GetCountSql = "select count(id)  from Sms_Log where " + SqlWhere;
        string SqlTable = "select *  from Sms_Log where " + SqlWhere + "  order by id desc ";

        BindQuerySearchModel(SqlWhere, GetCountSql, SqlTable);
    }
    /// <summary>
    /// 绑定搜索
    /// </summary>
    /// <param name="SqlWhere"></param>
    /// <param name="GetCountSql"></param>
    /// <param name="SqlTable"></param>
    private void BindQuerySearchModel(string SqlWhere, string GetCountSql, string SqlTable)
    {
        qm.TableName = TableName;
        qm.GetCountSql = GetCountSql;
        qm.GetTableSql = SqlTable;
        qm.ReturnPage = ReturnPage;
       
        qm.SqlWhere = SqlWhere;
        qm.WorkPage = ReturnPage;
        bindData(qm);
    }
    #region gvList显示

    private void bindData(FTchina.SearchQuery.QueryModel qm)
    {

       
        int pCurrentPage = (FTchina.basic.SafeRequest(Request["page"]).Length > 0) ? Convert.ToInt32(FTchina.basic.SafeRequest(Request["page"])) : 1;
        int pageSize = 15;//每页的数据
        int AllCount = Convert.ToInt32(FTchina.shujuku.GetDataTable(qm.GetCountSql).Rows[0][0].ToString());//数据总条目数
        litpager.Text = FTchina.Api.Pager.GetPagerWithPageName(qm.GetTableSql, AllCount, pCurrentPage, pageSize, qm.ReturnPage);
        gvList.DataSource = FTchina.shujuku.ShowForPage(qm.TableName, qm.SqlWhere, pCurrentPage, pageSize);
        gvList.DataBind();
        txbsearch.Text = qm.Key1;

    }
    #endregion





    #region GridView等控件导出到Excel
    protected void btnexcel_Click(object sender, EventArgs e)
    {
        //将分页去除
        gvList.Width = Unit.Percentage(100);
        gvList.AutoGenerateColumns = false;
        gvList.AllowPaging = false;
        string GetDateSql = string.Format(SqlTable, TableName);
        DataSet ds = FTchina.shujuku.GetDataSet(GetDateSql);
        gvList.DataSource = ds;
        gvList.DataBind();

        System.IO.StringWriter stringWrite = new System.IO.StringWriter();
        System.Web.UI.HtmlTextWriter writer = new System.Web.UI.HtmlTextWriter(stringWrite);
        gvList.RenderControl(writer);

        FTchina.Api.ToExcel.HtmlTableToExcel(stringWrite.ToString());
    }
    public override void VerifyRenderingInServerForm(Control control)
    {
        // 覆盖VerifyRenderingInServerForm方法，非常重要，否则系统会报错
        //base.VerifyRenderingInServerForm(control);
    }
    #endregion


}






